package net.tolkv.tdd;

import java.util.UUID;

public class Book extends Item {
	private String author;
	private String title;
	private String publisher;
	private String date;
	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public Book(String author) {
		super(UUID.randomUUID());
		this.setAuthor(author);
	}
	
	@Override
	public String toString() {
		return "Book [author=" + author + ", title=" + title + ", publisher="
				+ publisher + ", date=" + date + "]" + super.toString();
	}

	public Book(UUID id){
		super(id);
	}

	public Book(String string, String string2) {
		this(string);
		setTitle(string2);
	}

	public Book(String string, String string2, String string3) {
		this(string, string2);
		this.setPublisher(string3);
	}

	public Book(String string, String string2, String string3, String string4) {
		this(string, string2, string3);
		this.date = string4;
	}

	public String getAuthor() {
		return this.author;
	}

	public String getTitle() {
		String tmp=title;
		if(getPublisher()!=null) {
			tmp += " [" + getPublisher() + "]";
		}
		if(date!=null) {
			tmp+=  " [" + date + "]";
		}
		return tmp;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((author == null) ? 0 : author.hashCode());
		result = prime * result + ((date == null) ? 0 : date.hashCode());
		result = prime * result
				+ ((publisher == null) ? 0 : publisher.hashCode());
		result = prime * result + ((title == null) ? 0 : title.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Book other = (Book) obj;
		if (author == null) {
			if (other.author != null)
				return false;
		} else if (!author.equals(other.author))
			return false;
		if (date == null) {
			if (other.date != null)
				return false;
		} else if (!date.equals(other.date))
			return false;
		if (publisher == null) {
			if (other.publisher != null)
				return false;
		} else if (!publisher.equals(other.publisher))
			return false;
		if (title == null) {
			if (other.title != null)
				return false;
		} else if (!title.equals(other.title))
			return false;
		return true;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getPublisher() {
		return publisher;
	}

	public void setPublisher(String publisher) {
		this.publisher = publisher;
	}
	
	
}
